package com.cskaoyan._02charstream._04in;

import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/20 10:01
 **/
/*
使用转换流指定字符集
 */
public class Demo3 {
    public static void main(String[] args) throws IOException {
        // 创建输入流对象
        // FileReader不能指定字符集 使用的是默认的
        //FileReader reader = new FileReader("D:\\b.txt");
        //// read
        //char[] chars = new char[1024];
        //int readCount = reader.read(chars);
        //System.out.println(new String(chars,0,readCount));
        //// close
        //reader.close();

        // 转换流能够指定字符集
        InputStreamReader in = new InputStreamReader(new FileInputStream("D:\\b.txt"), "GBK");
        char[] chars = new char[1024];
        int readCount = in.read(chars);
        System.out.println(new String(chars,0,readCount));
        // close
        in.close();
    }
}
